<?php
////================ FORMS ===================
$MDOR = 'RD';
if (isset($_POST['ORP'])) {
    $OBJCTCL = $_POST['CID'];
    $OBJCTRC = $_POST['RID'];
    if ($_POST['AID'] == '') {
        $_POST['AID'] = 'null';
    }
    $OBJCTAC = $_POST['AID'];
    $ORTYPEPAY = $_POST['ORP'];
}
if (isset($_POST['OBJCTOR'])) {
    $OBJCTOR = $_POST['OBJCTOR'];
} elseif (isset($_GET['OID'])) {
    $OBJCTOR = $_GET['OID'];
}
if (!isset($_POST['CID'])) {
    $EXECMODE = 'SIMM';
    $_POST['CID'] = 0;
    $_POST['RID'] = 0;
    $_POST['AID'] = 0;
}

if (!isset($OBJCTOR)) {
    $MDOR = 'ED';
    $Order[0] = 1;
    $OBJCTOR = 0;
    $_POST['FraCalc'] = '0.00';
    $_POST['TmpOp'] = rand(1000000, 9999999);
    $ORVARS = $GLOBALS['MYT']->db_array("DESCRIBE Facturas");
    for ($v = 1; $v <= $ORVARS[0]; $v++) {
        $ORVAR = $ORVARS[$v]['Field'];
        $Order[1][$ORVAR] = '';
    }
} else {
    $Order = $GLOBALS['MYT']->db_array("SELECT * FROM facturas WHERE FraID = {$OBJCTOR}");
    $_POST['TmpOp'] = $OBJCTOR;
    $_POST['FraCalc'] = number_format($Order[1]['FraEnviado'], 2);
}
if (!isset($_POST['OBJCTRC']) && isset($OBJCTRC)) {
    $_POST['OBJCTRC'] = $OBJCTRC;
} elseif (!isset($OBJCTRC)) {
    $_POST['OBJCTRC'] = $Order[1]['FraBnfNumero'];
}
if (!isset($ORTYPEPAY)) {
    $ORTYPEPAY = $Order[1]['FraModoPago'];
}
if ($ORTYPEPAY == '') {
    $ORTYPEPAY = 1;
}
if (!isset($_POST['FraUrgente'])) {
    $_POST['FraUrgente'] = 0;
}
if (!isset($_POST['FraOrigen1'])) {
    $_POST['FraOrigen1'] = $_SESSION[$SESSCD];
}
if (!isset($_POST['RTQuot'])) {
    $_POST['RTQuot'] = 0;
}
if (!isset($_GET['COAG'])) {
    $_GET['COAG'] = 0;
}
if (!isset($_POST['FraMonCobro'])) {
    $_POST['FraMonCobro'] = 1;
}
if (!isset($_POST['FraMonDPagoISO'])) {
    $_POST['FraMonDPagoISO'] = 'BRL';
}

if (!isset($_POST['FraConcepto']) && $MDOR == 'ED') {
    $GetCLProps = $GLOBALS['MYT']->db_array("SELECT DATE(CliFechaAlta) AS CliFechaAlta FROM clientes WHERE CliNumero = {$OBJCTCL}");
    if ($GetCLProps[1]['CliFechaAlta'] == date("Y-m-d")) {
        $_POST['FraConcepto'] = 3;
    } else {
        $_POST['FraConcepto'] = 1;
    }
} elseif (!isset($_POST['FraConcepto'])) {
    $_POST['FraConcepto'] = null;
}
//=====================Invoice Form=========================
form_pr('InvoiceProperties', '', '', 'post');
// AML VARS
mn_field('hidden', 'ED', 'AMLCHECK', '', '', '', '', '');
mn_field('hidden', 'ED', 'AMLTYPE', '', '', '', '', '');
mn_field('hidden', 'ED', 'AMLDOCREQ', '', '', '', '', '');
mn_field('hidden', 'ED', 'AMLLEVEL', '', '', '', '', '');
mn_field('hidden', 'ED', 'AMLDESCR', '', '', '', '', '');
mn_field('hidden', 'ED', 'AML_alert', '', '', '', '', '');

mn_field('hidden', 'ED', 'OBJCTOR', $OBJCTOR, '', '', '', '');
mn_field('hidden', 'ED', 'OBJCTCL', $_POST['CID'], '', '', '', '');
mn_field('hidden', 'ED', 'OBJCTRC', $_POST['RID'], '', '', '', '');
mn_field('hidden', 'ED', 'OBJCTAC', $_POST['AID'], '', '', '', '');
mn_field('hidden', 'ED', 'TmpOp', $_POST['TmpOp'], '', '', '', '');
mn_field('hidden', 'ED', 'htr_ID', '', '', '', '', '');
mn_field('hidden', 'ED', 'FraCorresponsal', '', '', '', '', '');
mn_field('hidden', 'ED', 'FraConcepto', $_POST['FraConcepto'], '', '', '', '');
mn_field('hidden', 'ED', 'ctr_RegAmount', 0, '', '', '', '');

mn_field('hidden', 'ED', 'FraAgenciaPago', $_GET['COAG'], '', '', '', '');
mn_field('hidden', 'ED', 'FraComisionAg', 0, '', '', '', '');
mn_field('hidden', 'ED', 'FraComisionAgR', 0, '', '', '', '');
mn_field('hidden', 'ED', 'FraRetencion', 0, '', '', '', '');
mn_field('hidden', 'ED', 'FraComisionComercial', 0, '', '', '', '');
mn_field('hidden', 'ED', 'FraComisionCorr', 0, '', '', '', '');

mn_field('hidden', 'ED', 'no_prom', '', '', '', '', '');
mn_field('hidden', 'ED', 'prom_bonus', 0, '', '', '', '');
mn_field('hidden', 'ED', 'FraProm', 0, '', '', '', '');
mn_field('hidden', 'ED', 'FraTaxProm', 0, '', '', '', '');

if (isset($_POST['RCTP'])) {
    mn_field('hidden', 'ED', 'FraAdcRCTP', $_POST['RCTP'], '', '', '', '');
    if (!isset($_POST['rcvCode'])) {
        $_POST['rcvCode'] = '';
    } mn_field('hidden', 'ED', 'FraAdcrcvCode', $_POST['rcvCode'], '', '', '', '');
    if (!isset($_POST['rcvGood'])) {
        $_POST['rcvGood'] = '';
    } mn_field('hidden', 'ED', 'FraAdcrcvGood', $_POST['rcvGood'], '', '', '', '');
    if (!isset($_POST['rcvGroup'])) {
        $_POST['rcvGroup'] = '';
    } mn_field('hidden', 'ED', 'FraAdcrcvGroup', $_POST['rcvGroup'], '', '', '', '');
    if (!isset($_POST['rcvIdentifier'])) {
        $_POST['rcvIdentifier'] = '';
    } mn_field('hidden', 'ED', 'FraAdcrcvIdentifier', $_POST['rcvIdentifier'], '', '', '', '');
}
?>
<table width="100%"  border="0" cellspacing="1" cellpadding="1">
    <tr>
        <td colspan="2">
            <table width="100%"  border="0" cellpadding="2" cellspacing="1">
                <tr bgcolor="#C5D8D8">
                    <td><b>Recebido</b></td>
                    <td><b>Usar Saldo Amigo 10</b></td>
                    <td width="25%" bgcolor="#C5D8D8"><b>Taxa</b></td>
                    <td>Gerar Referência de Multibanco</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                </tr>
                <tr bgcolor="#8AB0B0">
                    <td>
                        <table><tr><td>
                                    <?php
                                    $GETCUR = "SELECT mc_ID AS ID, mc_MonedaISO AS NAME FROM hd_monedascobro WHERE mc_Flag = 1";
                                    mn_field('select', $MDOR, 'FraCalcISO', $Order[1]['FraMonCobro'], $GETCUR, '', '', '" readonly=""'); ?>
                                </td><td>
                                    <?php mn_field('text', $MDOR, 'FraCalc', $_POST['FraCalc'], '19', '12', '', 'INPNUM" onKeyUp="UnPopInvoice();'); ?>
                                </td></tr></table></td>
                    <td>	<input type="checkbox" name="saldo_amigo" value="1"/> </td>

                    <td>
                        <div id="ORTax">
                            <?php include('remittancefee.php'); ?>
                        </div>
                    </td>

                    <td><input type="checkbox" name="referencia"/></td>

                    <td align="center">
                        <div id="inv_Calc">
                            <?php include('remittancebuttoncalc.php'); ?>
                        </div>
                    </td>
                    
                    <td align="center"><?php
                                    if (!isset($EXECMODE)) {
                                        mn_field('button', $MDOR, 'PRSVOR', 'Executar Ordem', '19', '15', 'True', 'SUBMIT" disabled
		onClick="
		document.InvoiceProperties.PRSVOR.disabled=true;
		document.InvoiceProperties.Check.disabled=true;
			document.InvoiceProperties.action=\'_response/call.php?get=Compliance/prc_amlalert\';
			subform(\'InvoiceProperties\',\'ORResponse\');');
                                    } else {
                                        echo '(Simula&ccedil;&atilde;o)';
                                    } ?></td>
                            </tr>
                        </table></td>
                </tr>
                <tr>
                    <td colspan="6">
                        <div id="inv_Prom"></div>
                        <div id="inv_Result"></div></td>
                </tr>
                <tr>
                    <td><table width="100%"  border="0" cellpadding="3" cellspacing="0" bgcolor="#F0F0EC">
                            <tr>
                                <td>Origem:</td>
                                <td>
                        <?php
                                    mn_field('select', $MDOR, 'FraOrigen1', $_POST['FraOrigen1'], "SELECT OriNumero AS ID, OriNombre AS NAME FROM origenes
				WHERE (OriDominio = (SELECT OriDominio FROM origenes
					WHERE OriActivo = 1 AND OriNumero = {$_SESSION[$SESSCD]}
					AND (OriDominio != 100 AND OriDominio != OriNumero))
				OR OriNumero = {$_SESSION[$SESSCD]})
				AND OriActivo = 1", '', '', '"
	 onChange="document.InvoiceProperties.action=\'_response/call.php?get=Operative/remittancefee.php\';
		subform(\'InvoiceProperties\',\'ORTax\');
		document.InvoiceProperties.action=\'_response/call.php?get=Operative/remittancefare\';
		subform(\'InvoiceProperties\',\'ORTarifa\');
		UnPopInvoice();');
                        ?></td>
                            </tr>
                            <tr>
                                <td>Tarifa: </td>
                                <td><div id="ORTarifa"><?php include('remittancefare.php'); ?></div></td>
                            </tr>
                            <tr>
                                <td>Evento:</td>
                                <td><div id="Inv_event"><?php include('view/viewclientevent.php'); ?></div></td>
                            </tr>
                            <tr>
                                <td>Observacoes</td>
                                <td><?php echo mn_field('text', $MDOR, 'FraNotas', $Order[1]['FraNotas'], '100', '40', '', ''); ?></td>
                            </tr>
                        </table></td>
                    <td><table width="100%"  border="0" cellpadding="3" cellspacing="0" bgcolor="#CED9D9">
                            <tr>
                                <td>Enviado:            </td>
                                <td><?php
                                    mn_field('select', $MDOR, 'FraMonCobro', '', $GETCUR, '', '', '" readonly="');
                                    mn_field('text', $MDOR, 'FraEnviado', '', '19', '15', '', 'INPNUM" readonly="');
                        ?></td>
                                <td>Recebido:            </td>
                                <td><?php
                                    mn_field('select', $MDOR, 'FraEntregueISO', '', $GETCUR, '', '', '" readonly="');
                                    mn_field('text', $MDOR, 'FraEntregue', '', '19', '15', '', 'INPNUM" readonly="'); ?></td>
                            </tr>
                            <tr>
                                <td>A Pagar:            </td>
                                <td>
                        <?php
                                    mn_field('hidden', $MDOR, 'FraMonDPago', '', '', '', '', '');
                                    mn_field('text', $MDOR, 'MonDPagoISO', '', '3', '3', '', '" readonly="');
                                    mn_field('text', $MDOR, 'FraARecibir', '', '19', '15', '', 'INPNUM" readonly="');
                        ?></td>
                                <td>Câmbio:            </td>
                                <td><?php
                                    mn_field('text', $MDOR, 'FraTasa', '', '6', '4', '', 'INPNUM" readonly="');
                                    mn_field('hidden', $MDOR, 'FraTasaAgn', '', '6', '4', '', 'INPNUM" readonly="');
                        ?></td>
                            </tr>
                            <tr>
                                <td>Tipo: </td>
                                <td><?php mn_field('select', $MDOR, 'FraUrgente', $_POST['FraUrgente'], "SELECT REF AS ID, Name AS NAME FROM hd_transfertypes", '', '', '"
		onChange="document.InvoiceProperties.action=\'_response/call.php?get=Operative/remittancefee.php\';
		subform(\'InvoiceProperties\',\'ORTax\');
		UnPopInvoice();');
                        ?></td>
                                <td>Pagamento: </td>
                                <td><?php mn_field('select', $MDOR, 'FraModoPago', $ORTYPEPAY, "SELECT mp_ID AS ID, mp_ModoPago AS NAME
				FROM hd_modospago
				WHERE mp_ID = {$ORTYPEPAY}", '', 'True', '" readonly=" ');
                        ?></td>
                            </tr>
                            <tr>
                                <td>Mensagem:</td>
                                <td colspan="3"><?php echo mn_field('text', $MDOR, 'FraMensaje', $Order[1]['FraMensaje'], '100', '40', '', ''); ?></td>
                </tr>
            </table></td>
    </tr>
</table>
</form>